<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <s-table rowKey="id" size="default" :columns="columns" :data="loadData" ref="table">
        <span slot="created_at" slot-scope="text">{{ text | timeFormat }}</span>
        <span slot="action" slot-scope="text, record">
          <a-button type="link" @click="onCheckStore(record)" size="small">审核</a-button>
        </span>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { STable } from '@/components'
import { getCheckList, joinAlliance } from '@/api/store'

const columns = [
  {
    title: 'ID',
    dataIndex: 'id'
  },
  {
    title: '商城名称',
    dataIndex: 'store_name'
  },
  {
    title: '创建时间',
    dataIndex: 'created_at',
    scopedSlots: {
      customRender: 'created_at'
    }
  },
  {
    title: '操作',
    width: '250px',
    dataIndex: 'action',
    scopedSlots: {
      customRender: 'action'
    }
  }
]

export default {
  name: 'AllianceCheck',
  components: {
    STable
  },
  data () {
    return {
      columns,
      loadData: (params) => {
        return getCheckList(params)
          .then((res) => {
            return res.data
          })
          .catch((err) => {
            this.$message.error(err.message)
            this.$refs.table.localLoading = false
          })
      }
    }
  },
  created () {},
  methods: {
    onCheckStore: function (item) {
      this.$confirm({
        title: '提示',
        content: '是否同意该商城加入联盟？',
        okText: '同意',
        cancelText: '拒绝',
        onOk: () => {
          this.onAction(item.id, 1)
        },
        onCancel: () => {
          this.onAction(item.id, 0)
        }
      })
    },
    onAction: function (storeId, status) {
      this.$message.loading({ content: '处理中...', key: 'checkLoading' })
      joinAlliance({ storeId: storeId, status: status }).then(res => {
        if (res.code == 0) {
          this.$refs.table.refresh(true)
          this.$message.success({ content: res.msg, key: 'checkLoading' })
        } else {
          this.$message.warning({ content: res.msg, key: 'checkLoading' })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
